<?php
/** 
 * 求助事件发布/信息/详情
 *
 * Date: 2018/1/9 
 * @author jackzheng
 */
 
include_once(GZ_PATH . '/includes/affair_func.php');
class affairAction extends Action{
	
	/**
	 * 添加 发布事件
	*/
	public function add_affair(){
		GZ_Api::authToken();
		$data=array();
	 
	 	$img_list = _POST('img_list');
		$coordinate = _POST('coordinate');
	 	$award_money = _POST('award_money');
		$data['user_id'] = _POST('user_id',0);
		$data['rescue_type'] = _POST('type','');
		$data['address'] = _POST('address','');
		$data['award_money'] = !empty($award_money)?floatval($award_money):0;//奖励金额
		$data['reality_money'] = $data['award_money'];//实付金额
		$data['incident_desc'] = _POST('incident_desc','');//情况描述
		$data['user_coordinate'] = json_encode($coordinate);
		$data['order_sn'] = date("YmdHis",time()).$data['user_id'];
		$data['add_time'] = time();
		
		if(empty($data['award_money'])){GZ_API::message("奖励金额不能为空",2);}
		if(empty($data['address'])){GZ_API::message("地址不能为空",2);}
		
		$count_img = count($img_list);
		if($count_img>0){
			$data['user_imglist'] = json_encode($img_list);
		}else{
			$data['user_imglist'] = '';
		}
		
		//检查实名认证
		$sql="SELECT user_rank,is_validated FROM " .$GLOBALS['db']->table('users').
		" WHERE user_id=".$data['user_id']." LIMIT 1";
		$res_user = $this->getRow($sql);
		if($res_user['user_rank']==1){
			GZ_Api::message("未实名认证",2);
		}

		//检查进行中事件
		/*$sql = "SELECT count(*) FROM " . $this->table("rescue_log") .
		" WHERE user_id=".$data['user_id']." AND status<2";
   		$count_rescue = $this->getOne($sql);
		if($count_rescue>0){
			GZ_Api::message("您还有进行中事件，不能发布新信息",2);
		}*/
		
     	$res = $this->autoExecute($GLOBALS["db"]->table("rescue_log"),$data,"INSERT");
		if($res){

          GZ_Api::message("发布成功",1);
		  
      	}else{
			
          GZ_Api::message("发布失败",2);
		  
      	}
	}
	
	
	/**
	* 我的救助 我的求助
	* 事件 详情1（带地图）
	*
	*/
	public function get_info_map(){

		GZ_Api::authToken();
		 $user_id= _POST('user_id','');
		 $log_id = _POST('log_id','');
		 $type = _POST('actipn_type','');//type求助SH 救护CH
		 
		 $data = get_affair_info($user_id,$log_id,$type);//求助详情
		 
		if(!empty($data)){
			GZ_Api::outPut($data); 
		}else{
			 GZ_Api::message("数据不存在",0);
		}
		
	}
	
	
	/**
	*  发布事件 详情2
	*
	*/
	public function get_detail()
	{
		GZ_Api::authToken();
		$user_id =_POST('user_id','');
		$log_id =_POST('log_id','');
		$type = _POST('actipn_type','');//type求助SH 救护CH

		$data=get_detail_info($user_id,$log_id,$type);//求助详情
	 
		if(!empty($data)){
			GZ_Api::outPut($data); 
		}else{
			 GZ_Api::message("数据不存在",0);
		}
	}
	
	

}

?>